package view.actionlisteners;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.Date;

import view.AddressListView;

public final class SaveButtonActionListener implements ActionListener {

	private final AddressListView addressListView;

	public SaveButtonActionListener(AddressListView addressListView) {
		this.addressListView = addressListView;
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		FileOutputStream fos = null;
		ObjectOutputStream out = null;
		try {
			fos = new FileOutputStream((new Date().getTime() + ".ser"));
			out = new ObjectOutputStream(fos);
			out.writeObject(addressListView.getAddressList());
			out.close();
		} catch (IOException ex) {
			ex.printStackTrace();
		}
	}
}